#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
项目结构验证脚本
验证多线程增强转录系统文件是否正确组织
"""

import os
from scripts.utils import suppress_output

def verify_project_structure():
    """验证项目结构"""
    print("🔍 验证项目文件结构...")

    # 定义期望的文件结构
    expected_files = {
        "scripts/": [
            "enhanced_transcribe.py",
            "hybrid_transcribe.py",
            "transcribe_audio.py"
        ],
        "tests/": [
            "validate_multithread.py",
            "test_multithread.py",
            "README.md"
        ],
        "examples/": [
            "demo_multithread.py",
            "README.md"
        ],
        "docs/": [
            "增强转录系统使用指南.md",
            "FunASR本地部署.md"
        ],
        "": [
            "README.md",
            "CLAUDE.md",
            "LICENSE"
        ]
    }

    all_good = True

    for directory, files in expected_files.items():
        print(f"\n📁 检查 {directory if directory else '根目录'}:")

        for file in files:
            file_path = os.path.join(directory, file)
            if os.path.exists(file_path):
                print(f"  ✅ {file}")
            else:
                print(f"  ❌ {file} (缺失)")
                all_good = False

    return all_good

def verify_functionality():
    """验证功能正确性"""
    print("\n🧪 验证功能正确性...")

    try:
        # 测试验证脚本
        print("  测试验证脚本...")
        suppress_cmd = suppress_output()
        result = os.system(f"python tests/validate_multithread.py{suppress_cmd}")
        if result == 0:
            print("  ✅ 多线程功能验证脚本正常")
        else:
            print("  ❌ 多线程功能验证脚本失败")
            return False

        # 测试脚本帮助信息
        print("  测试脚本帮助信息...")
        result = os.system(f"python scripts/enhanced_transcribe.py --help{suppress_cmd}")
        if result == 0:
            print("  ✅ 增强转录脚本帮助信息正常")
        else:
            print("  ❌ 增强转录脚本帮助信息失败")
            return False

        return True

    except Exception as e:
        print(f"  ❌ 功能验证出错: {e}")
        return False

def main():
    """主函数"""
    print("=" * 60)
    print("🔧 多线程增强转录系统结构验证")
    print("=" * 60)

    # 验证文件结构
    structure_ok = verify_project_structure()

    # 验证功能
    if structure_ok:
        functionality_ok = verify_functionality()
    else:
        functionality_ok = False

    # 输出结果
    print("\n" + "=" * 60)
    if structure_ok and functionality_ok:
        print("✅ 项目结构和功能验证全部通过!")
        print("\n📋 快速开始:")
        print("  1. 激活虚拟环境: source venv_funasr/bin/activate")
        print("  2. 验证功能: python tests/validate_multithread.py")
        print("  3. 运行演示: python examples/demo_multithread.py")
        print("  4. 开始转录: python scripts/enhanced_transcribe.py input.mp4")
    else:
        print("❌ 验证失败，请检查缺失的文件或功能")
        print("\n🔧 故障排除:")
        print("  - 检查文件是否正确移动到对应目录")
        print("  - 确保虚拟环境已激活")
        print("  - 检查依赖包是否完整安装")
        return False

    return True

if __name__ == "__main__":
    success = main()
    if not success:
        exit(1)